#include "util.h"

#include <map>
#include <iostream>
#include <string>
#include <mutex>
#include <memory>
#include "threadpool.h"

std::mutex globalMutex;
int count=0;

class Manager
{
public:
    Manager(){}
    uint32_t getScore(const std::string& name)
    {
        auto it=stuMap.find(name);
        if (it==stuMap.end()){
            stuMap.insert({name,0});
        }
        return stuMap[name];
    }
    void insert(std::pair<std::string, uint32_t> stuPair)
    {
        stuMap.insert(stuPair);
    }
    void printAll()
    {
        for(const auto& item:stuMap){
            std::cout<<"name:"<<item.first<<"\t"<<"score:"<<item.second<<std::endl;
        }
    }
private:
    std::map<std::string,uint32_t> stuMap;
};

using scoreManage=daniel::Singleton<Manager>;

void insertData()
{
    std::lock_guard<std::mutex> lock(globalMutex);
    scoreManage::GetInstance()->insert(std::make_pair("daniel"+std::to_string(count),count));
    count++;
}

int main()
{
    std::shared_ptr<daniel::ThreadPool> thrs(new daniel::ThreadPool(4,8));
    for(size_t i=0;i<100;i++){
        thrs->addTask(insertData);
    }
    thrs->stop();
    scoreManage::GetInstance()->printAll();
}